﻿@using CREAPA.UL.Web.HtmlHelpers
@model CREAPA.Dominio.OS

     <script src="~/Scripts/js/original/InputMask.js"></script>
     <script src="~/Scripts/js/JavaScriptUtil.js"></script>

<script type="text/javascript">
    function setup(){
        new SizeLimit("DescricaoAnalise", 1000, "DescricaoAnaliseOut", "${size} / ${max}");
    }
</script>
<script language=JavaScript>
<!-- begin
    var sHors = "0" + 0;
    var sMins = "0" + 0;
    var sSecs = 0;
    function getSecs(c) {
        sSecs++;
        if (sSecs == 60) {
            sSecs = 0; sMins++;
            if (sMins <= 9) sMins = "0" + sMins;
        }
        if (sMins == 60) {
            sMins = "0" + 0; sHors++;
            if (sHors <= 9) sHors = "0" + sHors;
        }
        if (sSecs <= 9) sSecs = "0" + sSecs;
        clock1.innerHTML = sHors + "<font color=#000000>:</font>" + sMins + "<font color=#000000>:</font>" + sSecs;
        setTimeout('getSecs()', 1000);
    }
    var c = false;
    function ok(d) {
        if (d.checked) {
            c = true;
        } else {
            c = false;
            document.getElementById("TempoExec").innerText = TempoExec.value = 0;
            document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "M";
        }
    }
    function TempAutomatico(c) {
        if (c == true) {
            if (sHors >= 1) {
                document.getElementById("TempoExec").innerText = TempoExec.value = sHors;
                document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "H";
            } else {
                if (sMins >= 1) {
                    document.getElementById("TempoExec").innerText = TempoExec.value = sMins;
                    document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "M";
                } else {
                    if (sSecs >= 1) {
                        document.getElementById("TempoExec").innerText = TempoExec.value = sSecs;
                        document.getElementById("TempoUnidade").innerText = TempoUnidade.value = "S";
                    }
                }
            }
        }
        setTimeout('TempAutomatico(c)', 1000);
    }
    
   
   
    //-->
</SCRIPT>


@{
    ViewBag.Title = "Analisar";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Analisar OS</h2>

@{    
    var grid = new WebGrid(ViewBag.ListaOS); 
}

@{    
    var gridAnexo = new WebGrid(ViewBag.ListaDeAnexoOs); 
}

@using (Html.BeginForm("Analisar", "OS", FormMethod.Post,
          new { enctype = "multipart/form-data" })) {
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

<body onload="setup()">
    <fieldset>
        <legend>OS</legend>

        @Html.HiddenFor(model => model.Id)

         <div class="display-label">
       <b>  @Html.DisplayNameFor(model => model.Id):</b>
        @Html.DisplayFor(model => model.Id)
        </div> 
        <p />
          <p><div class="editor-label">
        <b> @Html.DisplayNameFor(model => model.DataCadOs):</b>
        @Html.DisplayFor(model => model.DataCadOs)
    </div>

        <div class="editor-field">
        <div class="login-msg">
            @Html.ValidationMessageFor(model => model.DataCadOs)</div>
        </div></p>
       <p> <div class="editor-label">
        <b> @Html.DisplayNameFor(model => model.PessoaCadastrou):</b>
            @Html.DisableableDropDownList("PessoaCadastrou",null,null, new { id = "cbGender1", style = "width:100px;"})
    </div>
<p>    
        <div class="editor-field">
        <div class="login-msg">
            @Html.ValidationMessageFor(model => model.PessoaInteressado)</div>
        </div></p>
        <p><div class="editor-label">
        <b> @Html.DisplayNameFor(model => model.PessoaInteressado):</b>
        @Html.DisableableDropDownList("PessoaInteressado",null,null, new { id = "cbGender2", style = "width:100px;"})
    </div>
        <div class="editor-field">
        <div class="login-msg">
            @Html.ValidationMessageFor(model => model.PessoaInteressado)</div>
        </div></p>
<p>
    <p> <div class="editor-label">
        <b> @Html.DisplayNameFor(model => model.Problema):</b>
        @Html.DropDownList("Problema")
    </div>
        <div class="editor-field">
        <div class="login-msg">
            @Html.ValidationMessageFor(model => model.Problema)</div>
        </div></p>
<p>
        <div class="display-label">
           <b> @Html.LabelFor(model => model.Descricao):</b>
              @Html.TextAreaFor(model => model.Descricao,new{id = "body", rows = "5", htmlEncodeOutput="true", maxlength = "500",@readonly = true})
            @Html.ValidationMessageFor(model => model.Descricao)
        </div></p>        
        <p>

        <p>  
    <div class="editor-label">
            @Html.LabelFor(model => model.Setor)
        </div>
        <div class="editor-field">
        <div class="login-msg">
            @Html.DropDownList("Setor")
            @Html.ValidationMessageFor(model => model.Setor)</div>
        </div></p>

@{
    if (ViewBag.ListaDeAnexoOs.Count > 0)
    {
         <p>
        <div class="editor-label">
           Anexos da OS
        </div>
        <div>
            @gridAnexo.GetHtml( tableStyle: "tableAO",
        alternatingRowStyle: "alternateAO",
        headerStyle: "headerAO",
        footerStyle: "footerAO",
        mode: WebGridPagerModes.FirstLast | WebGridPagerModes.NextPrevious,
        firstText: "Primeiro",
        previousText: "Anterior",
        nextText: "Próximo",
        lastText: "Último",columns: gridAnexo.Columns(
              gridAnexo.Column("Nome", header:"Nome", format: @<text><center>@item.Nome</center></text>),              
              gridAnexo.Column("Data", header:"Data de Cadastro", format: @<text>@item.Data</text>),
              gridAnexo.Column("PessoaCadastrou", header:"Cadastrado por", format: @<text><center>@item.PessoaCadastrou<center></text>),
              gridAnexo.Column("Download",   header: "Download",   format: @<text><center>@Html.ActionLink("Download", "Download", new { caminho = item.Caminho })</center></text>)))
        </div>
            </p>
    }
}

       <p>
        <div class="editor-label">
           Histórico da OS
        </div>
        <div>
            @grid.GetHtml( tableStyle: "tableAO",
        alternatingRowStyle: "alternateAO",
        headerStyle: "headerAO",
        footerStyle: "footerAO",
        mode: WebGridPagerModes.FirstLast | WebGridPagerModes.NextPrevious,
        firstText: "Primeiro",
        previousText: "Anterior",
        nextText: "Próximo",
        lastText: "Último",columns: grid.Columns(
              grid.Column("DescTipoSituacao", header:"Situacao", format: @<text><center>@item.DescTipoSituacao</center></text>),
              grid.Column("Descricao", header:"Descrição", format: @<text><div style='width: 30em'>@item.Descricao</div></text>),
              grid.Column("Data", header:"Data de Cadastro", format: @<text>@item.Data</text>),
              grid.Column("PessoaCadastrou", header:"Cadastrado por", format: @<text><center>@item.PessoaCadastrou<center></text>)))
        </div>
            </p>


        <p><div class="editor-label">
            @Html.LabelFor(model => model.TempoExec)
            <label style="margin-left:175px;">Tempo Automático</label>
        </div>

        <div class="editor-field">
        <div class="login-msg">
            @Html.EditorFor(model => model.TempoExec)
            @Html.ValidationMessageFor(model => model.TempoExec)
            @Html.DropDownListFor(model => model.TempoUnidade,
                      new SelectList(new List<SelectListItem> {
                      new SelectListItem{Value="M", Text="Minuto"},                           
                      new SelectListItem{Value="S", Text="Segundo"},                           
                           new SelectListItem{Value="H", Text="Hora"},
                           new SelectListItem{Value="D", Text="Dia"}}, "Value", "Text"))
            @Html.ValidationMessageFor(model => model.TempoUnidade)
             <font color="#FF0000"><span id="clock1"></span><script>setTimeout('getSecs()', 1000);</script></font>
                                                            <script>setTimeout('TempAutomatico()', 1000);</script>
            
            <input type="checkbox"onclick="ok(this);">    
    </div>      
        </div></p>

       <p> <div class="editor-label">
            @Html.DisplayNameFor(model => model.DescricaoAnalise):
        </div>
        <div class="editor-field">
        <div class="login-msg">
            @Html.TextAreaFor(model => model.DescricaoAnalise)
            @Html.ValidationMessageFor(model => model.DescricaoAnalise)</div>
               <div style="text-align:right;">
             <label id="DescricaoAnaliseOut"></label>
        </div>
         </div></p>
        
         <p> <div class="editor-label">
            Descrição do Documento Anexado (Não obrigatório):
        </div>
        
        <div  style="width: 500px;"> 
        <div class="editor-field">            
            <div class="login-msg">
            @Html.EditorFor(model => model.Anexo.Nome, new { style = "width: 50px;" })
            @Html.ValidationMessageFor(model => model.Anexo.Nome)            
            </div>
        </div><input type="file" name="FileUpload1"  /></div></p>  
        <p>

        <p>

            <input type="submit" value="Salvar" class="button"/>
            @Html.ActionLink("Voltar", "ListaPendentes",null,new { @class = "button2" })
           
        </p>
    </fieldset>
</body>

<script>
    jQuery(document).ready(function () {
        // verifica se existe algum elemento com a class
        if ($(".button").length) {
            // adiciona evento desabilitando o botão
            $(".button").on('click', function () {
                $(this).attr({
                    disabled: true
                });
                // descobrindo o form pai e enviando
                this.value = 'Enviando...';
                $(this).parents('form:first').submit();
            });
        }
    });
</script>


    <script type="text/javascript">
        $("#cb_Toggle").ready(function () {
            var $Gender = $("#cbGender1");

            $Gender.disableDropDownList();
        });
</script>   
    
<script type="text/javascript">
    $("#cb_Toggle").ready(function () {
        var $Gender = $("#cbGender2");

        $Gender.disableDropDownList();
    });
</script>  
    
    <script type="text/javascript">
        $("#cb_Toggle").ready(function () {
            var $Gender = $("#cbGender3");

            $Gender.disableDropDownList();
        });
</script> 
    
    <script type="text/javascript">
        $("#cb_Toggle").ready(function () {
            var $Gender = $("#cbGender4");

            $Gender.disableDropDownList();
        });
</script> 
    
    <script type="text/javascript">
        $("#cb_Toggle").ready(function () {
            var $Gender = $("#cbGender5");

            $Gender.disableDropDownList();
        });
</script> 
}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}


